'''
学生类
    学号:1 姓名:1 性别:1 住址:123
    学号:1 姓名:1 性别:1 住址:123
序列化：把一个对象变成字符串str或者字节串bytes
反序列化：把字符串或者字节串还原成对象
json - dumps / loads - 字符串
pickle - dumps / loads - 字节串
'''
import redis
import json
import pickle


class Studnet:

    def __init__(self, stuid, name, sex, addr):
        self.stuid = stuid
        self.name = name
        self.sex = sex
        self.addr = addr

    def __repr__(self):
        return '{}, {}, {}'.format(self.stuid, self.name,'男' if self.sex else '女')


stu1 = Studnet(1001, 'py1', True, 'cd')

client = redis.Redis(host='116.62.46.50', port=6379, password='smile123')
if client.ping():
    # client.set('stu', pickle.dumps(stu1))
    print(pickle.loads(client.get('stu')))
